package com.ztesoft.huangfu.learning.springboot.springbootaop.controller;

import com.ztesoft.huangfu.learning.springboot.springbootaop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/6/3
 * Time: 15:50
 * Version: 1.0
 * Description:通过自定义注解，然后根据注解拦截方法
 * 注解作为切点拦截
 * 也可以不用注解，包的路径作为切点，拦截该包下的所有方法
 **/
@RestController
@RequestMapping("/aop")
public class AspactController {

    @Autowired
    private UserService userService;
    //正常测试
    @GetMapping("/hello")
    public String hello(@RequestParam String name) {
        return "Hello " + name;
    }

    // 异常测试
    @GetMapping("/doError")
    public Object error() {
        return 1 / 0;
    }


    @RequestMapping("/user")
    public Object user(String id) {
        String res = userService.userMethod(id);
        return "user controller +"+res;
    }

    @RequestMapping("/student")
    public Object student(String name) {
        String res = userService.studentMethod(name);
        return "student controller +"+res;
    }
}
